package com.example.springboottestgit.controller.main;

import com.example.springboottestgit.bean.InstructData;

import java.io.IOException;
import java.nio.file.*;
import java.util.Random;
import java.util.concurrent.TimeUnit;

public class Main {
    public static void main(String[] args) throws IOException, InterruptedException {
        String fileName = "zzz";

        WatchService watchService = FileSystems.getDefault().newWatchService();

        // 监控的目录
        String dirPath = "D:/file";

        // 注册监控事件
        Path dir = Paths.get(dirPath);
        dir.register(watchService, StandardWatchEventKinds.ENTRY_CREATE);
        long endTime = System.currentTimeMillis() + 50000;

        // 开始监控
        while (true) {
            System.out.println("==============================");
            //WatchKey key = watchService.take();
            WatchKey key = watchService.poll(endTime - System.currentTimeMillis(), TimeUnit.MILLISECONDS);
            if (key != null) {
                for (WatchEvent<?> event : key.pollEvents()) {
                    WatchEvent.Kind<?> kind = event.kind();
                    // 如果是新增文件事件
                    if (kind == StandardWatchEventKinds.ENTRY_CREATE) {
                        Path createdFile = (Path) event.context();
                        System.out.println("新增文件：" + createdFile);
                        // 在这里处理新增文件
                    }
                }
                if (!key.reset()) {
                    break; // WatchService has been closed
                }
            }
            if (System.currentTimeMillis() >= endTime) {
                System.out.println("No new files detected within the timeout. Closing WatchService.");
                watchService.close();
                break;
            }
        }

        System.out.println("没有新的文件增加");



/*        double a = 81.03 * 601.94;
        System.out.println(a);
        System.out.println("Margin".toUpperCase());
        System.out.println("Tb_Expire".toUpperCase());
        System.out.println("Tb_Notice_Term".toUpperCase());
        System.out.println("[350001]FJYS[GK]2023106-2".length());

        List<LawVO> result = new ArrayList<>();

        LawVO vo = new LawVO();
        vo.setCode("1");
        vo.setOutput("fsd");
        vo.setQuestion("fsd");
        //vo.setName("zfsdf");

        result.add(vo);

        List<Map<String, Object>> list = JSONObject.parseObject(JSONObject.toJSONString(result), List.class);
        System.out.println(JSONObject.toJSONString(list));


        String filePath = "D:/file/file.json"; // JSON文件路径

        FileReader reader = new FileReader(filePath);
        BufferedReader bufferedReader = new BufferedReader(reader);
        StringBuilder stringBuilder = new StringBuilder();
        String line;

        while ((line = bufferedReader.readLine()) != null) {
            stringBuilder.append(line);
        }
        bufferedReader.close();

        String jsonStr = stringBuilder.toString();
        LawDTO dto=JSONObject.parseObject(jsonStr,LawDTO.class);

        System.out.println(jsonStr);
        System.out.println("+++++++");
        System.out.println(JSONObject.toJSONString(dto));*/

//        String url ="http://192.168.80.35:19327/v1/completions";
//        InputVO vo=new InputVO();
//        vo.setPrompt("招标文件的质疑时效期间为获取招标文件之日起5个工作日内提出这句话是对的吗");
//        String param= JSONObject.toJSONString(vo);
//
//        String result = cn.hutool.http.HttpUtil.createPost(url)
//                //这个请求头.header是自己项目需要加的，可以省略
//                .header("Content-Type", "application/json")
//                //这两个请求头是项目需要加的，可以省略
//                //传输参数
//                .body(param).execute().body();
//
//        OutputVO out= JSONObject.parseObject(result, OutputVO.class);
//        String text=out.getChoices().get(0).getText();
//        System.out.println(text);
//
//        System.out.println(text.startsWith("是的")||text.startsWith("符合"));


    }

    public static InstructData bzj() {
        Random random = new Random();
        int ysmin = 10000;
        int ysmax = 1000000;

        int ys = random.nextInt(ysmax - ysmin + 1) + ysmin;
        int ysje = ys * 100;
        int zgbzj = (int) (ysje * 0.02);

        System.out.println("采购项目预算金额：" + ysje);
        System.out.println("最高保证金额：" + zgbzj);
        int bzjmin = 10000;
        int bzjmax = 1000000;
        int bzj = random.nextInt(bzjmax - bzjmin + 1) + bzjmin;
        System.out.println("投标保证金：" + bzj);

        String flag = bzj <= ysje * 0.02 ? "未超过" : "超过";
        System.out.println(flag);
        String d = bzj == ysje * 0.02 ? "等于" : flag;


        String instruction = "根据《中华人民共和国政府采购法实施条例》规定，投标保证金不得超过采购项目预算金额的2%，那么请问投标保证金b元是否超过采购项目预算金额y元的2%？";
        String input = "";
        String output = "#，在这个例子中，采购项目预算金额是y元，采购项目预算金额的2% = y元 × 2% = y元 × 0.02 = z元，由于投标保证金金额b元d计算出的预算金额的2%（z元），所以投标保证金b元#采购项目预算金额y的2%。";

        instruction = instruction.replace("b", String.valueOf(bzj)).replace("y", String.valueOf(ysje));
        output = output.replaceAll("b", String.valueOf(bzj)).replace("y", String.valueOf(ysje)).replace("#", flag).replace("d", d).replace("z", String.valueOf(zgbzj));

        InstructData demo = new InstructData();
        demo.setInstruction(instruction);
        demo.setInput("");
        demo.setOutput(output);
        return demo;
    }
}
